<style>
.layui-form-label { width: 30%!important;}
.layui-form-label div{ font-size: 12px;font-weight: normal;color: #AC6363;}
.layui-input-block {margin-left: 30%;}
.layui-form-item{border-bottom: 1px solid #f5f5f5;}
.layui-card-body, .layui-card-header, .layui-form-label, .layui-form-mid, .layui-form-select, .layui-input-block, .layui-input-inline, .layui-textarea { width: 300px; }
.regular .layui-form-select{float: left; width: 150px;}
</style>

<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	
		<!-- END RIBBON -->
		<div class="content">
			<div class="panel panel-default panel-intro">
				<div class="panel-heading">
					<div class="panel-lead">
						<em>CMS - 修改字段</em>
						...
					</div>
				</div>
				<div class="panel-body">
					<div id="myTabContent" class="tab-content">
						<div class="tab-pane fade active in" id="one">
							<div class="widget-body no-padding">
								<div class="bootstrap-table">
									
									<div class="fixed-table-toolbar">
										<div class="bs-bars pull-left">
											<div id="toolbar" class="toolbar">
												<a href="javascript:window.location.reload();" class="btn btn-primary btn-refresh" title="刷新">
													<i class="fa fa-refresh"></i>
												</a>
											</div>
										</div>
										<div class="columns columns-right btn-group pull-right">
											
										</div>
									</div>
									<div class="fixed-table-container" style="padding-bottom: 0px;">


<div class="fixed-table-body">
<div id="main" role="main">
	<div class="tab-content tab-addtabs">
		<div>
			<div class="row">
				<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
						<div class="content">
						<form class="layui-form" >
								<div class="layui-form-item">
									<label class="layui-form-label">
										字段类型
										
									</label>
									<div class="layui-input-block">
										<select class="layui-input" id="type" lay-filter="type">
											<option value="0">请选择字段类型</option>
											<option value="text" {eq name="info['if_type']" value="text"}selected{/eq}>单行文本</option>
											<option value="textarea" {eq name="info['if_type']" value="textarea"}selected{/eq}>多行文本</option>
											<option value="int" {eq name="info['if_type']" value="int"}selected{/eq}>数字</option>
											<!--JS插件-->
											<option value="editor" {eq name="info['if_type']" value="editor"}selected{/eq}>编辑器</option>
											<option value="enclosure" {eq name="info['if_type']" value="enclosure"}selected{/eq}>附件</option>
											<option value="image" {eq name="info['if_type']" value="image"}selected{/eq}>单图片</option>
											<option value="images" {eq name="info['if_type']" value="images"}selected{/eq}>多图片</option>
											<!--根据选择变动-->   
											<option value="radio" {eq name="info['if_type']" value="radio"}selected{/eq}>单选</option>
											<option value="checkbox" {eq name="info['if_type']" value="checkbox"}selected{/eq}>多选</option>
											<option value="select" {eq name="info['if_type']" value="select"}selected{/eq}>列表</option>
										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label" style="padding-bottom:0">
										字段名
										<div>(只能由英文字母、数字和下划线组成，并且仅能字母开头，不以下划线结尾)</div>
									</label>
									<div class="layui-input-block">
										<input type="text" class="layui-input" id="name" value="{$info.if_name}">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label" style="padding-bottom:0"> 
										字段别名
										<div>例如：文章标题</div>
									</label>
									<div class="layui-input-block">
										<input type="text" class="layui-input" id="title" value="{$info.if_title}">
									</div>
								</div>
								<div class="layui-form-item" id="A3" style="display:none">
									<label class="layui-form-label" style="padding-bottom:0"> 
										字段长度
										<div>例如：11，如果包含小数，还可以为10,2，使用decimal类型</div>
									</label>
									<div class="layui-input-block">
										<input type="text" class="layui-input" id="length" value="{$info.if_length}">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label" style="padding-bottom:0">
										字段提示
										<div>显示在字段别名下方作为表单输入提示</div>
									</label>
									<div class="layui-input-block">
										<textarea style="min-height: 60px;width: 600px;margin-bottom: 10px;" class="layui-textarea" id="des">{$info.if_des}</textarea>
									</div>
								</div>
								<!--一些特殊的类型附加值-->
								<div class="layui-form-item" id="A2" style="display:none">
									<label class="layui-form-label">
										编辑器类型
									</label>
									<div class="layui-input-block">
										<select class="layui-input" id="text">
											<option value="0">请选择编辑器类型</option>
											<option value="1" {eq name="info['if_text']" value="1"}selected{/eq}>wangEditor</option>
											<option value="2" {eq name="info['if_text']" value="2"}selected{/eq}>Markdown</option>
											<option value="3" {eq name="info['if_text']" value="3"}selected{/eq}>Layui</option>
										</select>
									</div>
								</div>
								<div class="layui-form-item" id="A1" style="display:none">
									<label class="layui-form-label" style="padding-bottom:0">
										相关参数
										<div>设置表单相关属性</div>
									</label>
									<div class="layui-input-block">
										<textarea style="min-height: 60px;width: 600px;margin-bottom: 10px;" class="layui-textarea" id="content" placeholder="格式为：key|val,key|val...">{$info.if_content}</textarea>
									</div>
								</div>
								<!--END-->
								<div class="layui-form-item">
									<label class="layui-form-label">
										默认值
									</label>
									<div class="layui-input-block">
										<input type="text" class="layui-input" id="default" value="{$info.if_default}">
									</div>
								</div>
								<div class="layui-form-item" id="A4">
									<label class="layui-form-label" style="padding-bottom:0">
										字符长度取值范围
										<div>系统将在表单提交时检测数据长度范围是否符合要求，如果不想限制长度请留空</div>
									</label>
									<div class="layui-input-block">
										<input type="text" class="layui-input" id="min" style="width:100px;float: left;" placeholder="最小值" value="{$info.if_min}">
										<div style="width: 20px;float: left;text-align: center;line-height: 38px;">-</div>
										<input type="text" class="layui-input" id="max" style="width:100px;float: left;" placeholder="最大值" value="{$info.if_max}">
									</div>
								</div>
								<div class="layui-form-item" id="A5">
									<label class="layui-form-label" style="padding-bottom:0">
										数据校验正则
										<div>系统将通过此正则校验表单提交的数据合法性，如果不想校验数据请留空</div>
									</label>
									<div class="layui-input-block regular" style="width: 600px;">
										<input type="text" class="layui-input" id="regular" style="float: left;width: 300px;" value="{$info.if_regular}">
										<select class="layui-input" id="regular_type" lay-filter="regular_type">
											<option value="">常用正则</option>
											<option value="/^[0-9.-]+$/" {if condition="$info['if_regular'] == '/^[0-9.-]+$/'"}selected{/if}>数字</option>
											<option value="/^[0-9-]+$/" {if condition="$info['if_regular'] == '/^[0-9-]+$/'"}selected{/if}>整数</option>
											<option value="/^[a-z]+$/i" {if condition="$info['if_regular'] == '/^[a-z]+$/i'"}selected{/if}> 字母</option>
											<option value="/^[0-9a-z]+$/i" {if condition="$info['if_regular'] == '/^[0-9a-z]+$/i'"}selected{/if}>数字+字母</option>
											<option value="/^[a-z0-9]([a-z0-9]*[-_\.]?[a-z0-9]+)*@[a-z0-9]*([-_\.]?[a-z0-9]+)+[\.][a-z0-9]{2,3}([\.][a-z0-9]{2})?$/i" <?php if($info['if_regular'] == '/^[a-z0-9]([a-z0-9]*[-_\.]?[a-z0-9]+)*@[a-z0-9]*([-_\.]?[a-z0-9]+)+[\.][a-z0-9]{2,3}([\.][a-z0-9]{2})/i') {echo 'selected';}?>>E-mail</option>
											<option value="/^[0-9]{5,20}$/" <?php if($info['if_regular'] == '/^[0-9]{5,20}$/'){ echo 'selected';}?> >QQ</option>
											<option value="/^(1)[0-9]{10}$/" <?php if($info['if_regular'] == '/^(1)[0-9]{10}$/'){ echo 'selected';}?> >手机号码</option>
											<option value="/^[0-9-]{6,13}$/" <?php if($info['if_regular'] == '/^[0-9-]{6,13}$/'){ echo 'selected';}?> >电话号码</option>
											<option value="/^[0-9]{6}$/" <?php if($info['if_regular'] == '/^[0-9]{6}$/'){ echo 'selected';}?> >邮政编码</option>
										</select>
									</div>
								</div>
								<div class="layui-form-item" id="A6">
									<label class="layui-form-label">
										数据校验未通过的提示信息
									</label>
									<div class="layui-input-block">
										<input type="text" class="layui-input" id="alert" value="{$info.if_alert}">
									</div>
								</div>

								<div class="layui-form-item">
									<label class="layui-form-label">
										必填字段
									</label>
									<div class="layui-input-block">
										<input type="checkbox" name="notnull" lay-skin="switch" {eq name="info['if_notnull']" value="1"}checked{/eq} >
									</div>
								</div>

								<div class="layui-form-item">
									<label class="layui-form-label">
										唯一字段
									</label>
									<div class="layui-input-block">
										<input type="checkbox" name="only" lay-skin="switch" {eq name="info['if_only']" value="1"}checked{/eq} >
									</div>
								</div>

								<div class="layui-form-item" style="{if condition="$status != 1"}display:none{/if}">
									<label class="layui-form-label">
										附表字段
									</label>
									<div class="layui-input-block">
										<input type="checkbox" name="is_data" lay-skin="switch" {eq name="info['if_is_data']" value="1"}checked{/eq} >
									</div>
								</div>

								<div class="layui-form-item">
									<div class="layui-input-block">
										<button type="button" class="layui-btn layui-btn-sm layui-btn-normal">立即修改</button>
										<button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">重置</button>
									</div>
								</div>

						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>




										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>




												
<script>
tab('{$info.if_type}');
function tab(t) {
	if (t=='text' || t=='textarea' || t=='int' || t=='enclosure' || t=='image') {
		$('#A1').hide();
		$('#A2').hide();
		$('#A3').show();
		$('#A4').show();
		$('#A5').show();
		$('#A6').show();
	// 单选框+多选框+下拉菜单	
	} else if (t=='radio' || t=='checkbox' || t=='select') {
		$('#A1').show();
		$('#A2').hide();
		$('#A3').show();
		$('#A4').hide();
		$('#A5').hide();
		$('#A6').hide();
		$('#min').val('');
		$('#max').val('');
		$('#regular').val('');
		$('#alert').val('');
	} else if (t=='editor') {
		$('#A2').show();
		$('#A1').hide();
		$('#A3').hide();
		$('#A4').hide();
		$('#A5').hide();
		$('#A6').hide();
		$('#min').val('');
		$('#max').val('');
		$('#regular').val('');
		$('#alert').val('');
	} else {
		$('#A1').hide();
		$('#A2').hide();
		$('#A3').hide();
	}
}

layui.use(['form'], function(){
	var form = layui.form;
	// 切换正则表达式
	form.on('select(regular_type)', function(data){
		$('#regular').val(data.value);
	}); 
	// 切换字段类型选择器
	form.on('select(type)', function(data){
		var t = data.value;
		tab(t);
	});
});

$('.layui-btn-normal').click(function(){
	var type     = $('#type').val();
	var name     = $('#name').val();
	var title    = $('#title').val();
	var length   = $('#length').val();
	var des      = $('#des').val();
	var text     = $('#text').val();
	var content  = $('#content').val();
	var default2 = $('#default').val();
	var min      = $('#min').val();
	var max      = $('#max').val();
	var regular  = $('#regular').val();
	var alert    = $('#alert').val();
	var notnull  = 0;
	var only     = 0;
	var is_data  = 0;
	if ($("input[name='notnull']").is(':checked')) { notnull = 1; }
	if ($("input[name='only']").is(':checked')) { only = 1; }
	if ($("input[name='is_data']").is(':checked')) { is_data = 1; }
	
	var data = {
		'pid':'{$info.if_id}',
		'type':type,
		'name':name,
		'title':title,
		'length':length,
		'des':des,
		'text':text,
		'content':content,
		'default2':default2,
		'min':min,
		'max':max,
		'regular':regular,
		'alert':alert,
		'notnull':notnull,
		'only': only,
		'is_data':is_data
	};

	if (type == '' || type == 0) { $.thinkmimi({Content : '请选择字段类型', Type:2, Align:'right', OutTime:2000});return false; }
	if (name == '') { $.thinkmimi({Content : '请输入字段名称', Type:2, Align:'right', OutTime:2000});return false; }
	if (title == '') { $.thinkmimi({Content : '请输入字段别名', Type:2, Align:'right', OutTime:2000});return false; }
	if (type == 'editor' && (text == '' || text ==0)) { $.thinkmimi({Content : '请选择编辑器类型', Type:2, Align:'right', OutTime:2000});return false; }

	$.ajax({
		type: 'post',
		data: data,
		async: false,
		url: "{:url('upd')}",
		success: function(data) {
			var array = eval('('+data+')');
			if (array['code'] == '01') {
				$.thinkmimi({Content : array['msg'], Type:2, Align:'right', OutTime:2000});
			} else {
				$.thinkmimi({Content : array['msg'], Type:1, Align:'right', OutTime:2000,});
				window.setTimeout(function(){
					window.location.href = '{:url("field/index", ["pid"=>$info["im_id"]])}';
				}, 700);
			}
		}
	});

});

</script>